package com.dang.alex.web.servlet;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.dang.alex.model.CarItem;

/**
 * Servlet implementation class DelcarServlet
 */
@WebServlet("/DelcarServlet.do")
public class DelcarServlet extends HttpServlet {
 
    public DelcarServlet() {
        super();
    }


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session =request.getSession();
		Map<Integer,CarItem> s_car=(Map<Integer,CarItem>)session.getAttribute("s_car");
		if(s_car==null) {
			response.sendRedirect("cart_list.jsp");
		}else {
			for(Map.Entry<Integer,CarItem> entry:s_car.entrySet()) {
				s_car.remove(entry.getKey());
			}
		}
		request.getSession().setAttribute("s_car", s_car);
		response.sendRedirect("cart_list.jsp");
	}

}
